n = float(input())

m = int(n)

if len(str(m)) == 4 and n - int(n) == 0:
    
    m1 = m // 1000
    m2 = m // 100 % 10
    m3 = m // 10 % 10
    m4 = m % 10
    m5 = m // 100
    m6 = m // 10 % 100
    m7 = m % 100
    m8 = m // 10
    m9 = m % 1000
    m10 = m
    
    max1 = 0
    
    b1, b2, b3, b4, b5, b6, b7, b8, b9, b10 = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    
    
    for i in range(2, m1):
        if m1 % i == 0:
            b1 += 1
    for i in range(2, m2):
        if m2 % i == 0:
            b2 += 1
    
    for i in range(2, m3):
        if m3 % i == 0:
            b3 += 1
    
    for i in range(2, m4):
        if m4 % i == 0:
            b4 += 1
    
    for i in range(2, m5):
        if m5 % i == 0:
            b5 += 1
    
    for i in range(2, m6):
        if m6 % i == 0:
            b6 += 1
    
    for i in range(2, m7):
        if m7 % i == 0:
            b7 += 1
    
    for i in range(2, m8):
        if m8 % i == 0:
            b8 += 1
    
    for i in range(2, m9):
        if m9 % i == 0:
            b9 += 1
    
    for i in range(2, m10):
        if m10 % i == 0:
            b10 += 1
    
    
    if b1 == 0:
        if max1 < m1:
            max1 = m1
    
    if b2 == 0:
        if max1 < m2:
            max1 = m2
    
    if b3 == 0:
        if max1 < m3:
            max1 = m3
    
    if b4 == 0:
        if max1 < m4:
            max1 = m4
    
    if b5 == 0:
        if max1 < m5:
            max1 = m5
    
    if b6 == 0:
        if max1 < m6:
            max1 = m6
    
    if b7 == 0:
        if max1 < m7:
            max1 = m7
    
    if b8 == 0:
        if max1 < m8:
            max1 = m8
    
    if b9 == 0:
        if max1 < m9:
            max1 = m9
    
    if b10 == 0:
        if max1 < m10:
            max1 = m10
    
    print(max1)
else:
    print("0")
